package pos.domain;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class ProductStore {

	private static ProductStore ps;

	private List products;

	public static synchronized ProductStore getInstance() {
		if (ps == null)
			ps = new ProductStore();
		return ps;
	}

	private ProductStore() {
		products = new LinkedList();
		Product p1 = new Product();
		p1.setDescription("Monitor");
		p1.setPrice(170);
		p1.setProductID("1");

		Product p2 = new Product();
		p2.setDescription("Teclado");
		p2.setPrice(20);
		p2.setProductID("2");

		Product p3 = new Product();
		p3.setDescription("Ratón");
		p3.setPrice(10);
		p3.setProductID("3");

		Product p4 = new Product();
		p4.setDescription("CPU");
		p4.setPrice(600);
		p4.setProductID("4");

		products.add(p1);
		products.add(p2);
		products.add(p3);
		products.add(p4);

	}

	public List getProducts() {
		return products;
	}

	public Product getProduct(String productID) {
		Product result = null;
		for (Iterator iter = products.iterator(); iter.hasNext();) {
			Product p = (Product) iter.next();
			if (p.getProductID().compareTo(productID) == 0) {
				result = p;
			}
		}
		return result;
	}
}
